package com.shuoyue.ycgk.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;


public class XToast {

    private static Toast toast;

    /**
     * @param context
     * @param text
     * @return
     * @Title: toast
     * @Description: 默认吐丝方法，居中弹出
     */
    public static void toast(Context context, String text) {
        if (context == null) return;
        if (text != null && toast == null) {
            toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(text);
        }
        toast.show();
    }

    /**
     * @param context
     * @param text
     * @return
     * @Title: toast
     * @Description: 吐丝方法，居中弹出
     */
    public static void toast(Context context, String text, int duration) {
        if (context == null) return;
        if (text != null && toast == null) {
            toast = Toast.makeText(context, text, duration);
            toast.setGravity(Gravity.CENTER, 0, 0);

        } else {
            toast.setText(text);
        }
        toast.show();
    }

}